package com.gps.pe.service;

import java.sql.Connection;
import java.util.List;

import org.apache.log4j.Logger;

import com.gps.pe.dao.DAOManagerFactory;
import com.gps.pe.dao.DatabaseConnection;
import com.gps.pe.exception.DAOException;
import com.gps.pe.exception.PeException;
import com.gps.pe.model.Role;

/**
 * Class provide Role Service
 * @author GPS
 *
 */
public class RoleService implements IRoleService {

	private static final Logger LOGGER = Logger.getLogger(RoleService.class);
	
	/**
	 * Service to get Role by Id
	 */
	@Override
	public Role getRoleById(int roleId) throws PeException {
		Role role = null;
		LOGGER.info("Service started - Get role by Id [" + roleId + "]");
		Connection connection = DatabaseConnection.getInstance().getConnection();
		DAOManagerFactory daoFactory = new DAOManagerFactory(connection);
		try {
		daoFactory.beginTransaction();
		LOGGER.info("Begin transaction...");
		role = daoFactory.getRoleDAO().getRole(roleId);
		} catch (DAOException e) {
			LOGGER.error("DAOException to get Role by Id [" + roleId + "]");
			daoFactory.rollbackTransaction();
			throw new PeException("Problem to fetch data for RoleId [" + roleId + "]" , e);
		}
		daoFactory.endTransaction();
		LOGGER.info("Transaction ended successfully...");
		LOGGER.info("Service ended successfully - Get role by Id [" + roleId + "]");
		return role;
	}

	@Override
	public List<Role> getAllRole() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean addRole(Role role) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean updateRole(Role role) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean deleteRole(Role role) {
		// TODO Auto-generated method stub
		return false;
	}
}
